﻿#pragma once
#include <QMap>
#include "ComponentBase.h"


class HttpServer;

class WCSReciver : public ComponentBase
{
	Q_OBJECT

public:
	WCSReciver(QObject* parent);
	~WCSReciver();

	// 订阅接口，提供给其它组件订阅本组件消息的接口
	virtual bool RegisterSubscriberFunction(int type, Callback callback) override;

protected:
	// 组件初始化处理函数
	virtual int ComponentInit() override;
	/*自检接口*/
	virtual bool ComponentCheckSelfState() override;
	/*复位接口*/
	virtual bool ComponentSelfReset() override;

private:
	int ReciverMsg(const QString& type, const QByteArray& req, QByteArray& ans);

	int WCSMsgProcess(const QString& cmd, const QByteArray& req, QByteArray& ans);
	int GratingProcess(const QString& cmd, const QByteArray& req, QByteArray& ans);

	QByteArray CreateAnsData(int code, const QString& msg, const QByteArray& usrData);

private:
	/*获取命令编码*/
	WCSMsgType GetWCSCmdNum(const QString& type, MethodType method);
	GratingMsgType GetGratingCmdNum(const QString& type, MethodType method);
private:
	QMap<WCSMsgType, QVector<std::function<int(const QByteArray&)>>> m_subscribers;
	HttpServer* m_server = nullptr;
	ComponentBase* m_stackInfo;
	ComponentBase* m_grating = nullptr;
};
